﻿
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script src="/js/header.js"></script>
    <title>秒付宝-报表</title>
    <link href="/lib/easyui/default/easyui.css" rel="stylesheet" />
    <link href="/lib/sumoselect/sumoselect.css" rel="stylesheet" />
    <script type="text/javascript" src="/lib/date/wdatepicker.js"></script>
    <script type="text/javascript" src="/lib/sumoselect/jquery.sumoselect.js"></script>
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch" onsubmit="return false;">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline">
                    <div class="input-sm">最后更新时间：<label id="lastUpdateDate" style="font-weight:bold;"></label></div>
                </div>
                <div class="pull-right">


                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">公司名称：</label>
                        <select multiple="multiple" class="search-box-sel-all" name="companyIds" style="height: 31px;padding: 3px 12px;width:150px;"></select>
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">类型：</label>
                        <select class="form-control" id="reportType" name="reportType">
                            <option value="1" selected>存款</option>
                            <option value="2">付款</option>
                        </select>
                    </div>

                    <div class="input-group">
                        <label class="input-group-addon m5_l">时间：</label>
                        <input id="d421" class="Wdate wd125" name="startTime" type="text" onfocus="WdatePicker({maxDate:'%y-%M-%d'})" autocomplete="off" />--<input id="d422" class="Wdate wd125" name="endTime" type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                    </div>

                    <button type="button" class="btn btn-default btn-sm active" id="btnSearch" onclick="return doSearch();"><span class="glyphicon glyphicon-search"></span> 搜索</button>

                </div>
            </div>
        </form>
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="easyui-treegrid" id="treegrid"></table>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">

        var treegrid;
        var companyIds = $("select[name='companyIds']");

        $(function () {

            $("input[name='startTime']").val(FlashPay.Util.GetDateStr(-1));
            $("input[name='endTime']").val(FlashPay.Util.GetDateStr(0));

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Report/GetCompany/",
                data: null,
                success: function (response) {
                    if (response.success) {

                        companyIds.empty();
                        if (response.data != null) {
                            $.each(response.data, function (i, item) {
                                companyIds.append("<option value='" + item.companyID + "'>" + item.companyName + "</option >");
                            });
                            $("select[name='companyIds']").SumoSelect({ okCancelInMulti: true, selectAll: true });
                        }
                    } else {
                    }
                },
                error: function (e) {
                    cover.Remove();
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
                }
            });

            doSearch();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Report/GetLastUpdateDate/",
                data: null,
                success: function (response) {
                    if (response.success) {
                        $("label#lastUpdateDate").html(response.data);
                    }
                }
            });
            
        });

        function doSearch() {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            var data = $("#formSearch").serializeObject();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Report/getBankCardDetail",
                data: data,
                success: function (response) {

                    cover.Remove();

                    var str = "付款";

                    var reportType = $('#reportType option:selected').val();
                    if (reportType == 1) {
                        str = "存款";
                    }
                    treegrid = $('#treegrid').treegrid({
                        loadMsg: '数据加载中，请稍后……',
                        rownumbers: true,
                        idField: 'index',
                        treeField: 'companyName',
                        height: $(window).height()-70,
                        data: response,
                        columns: [[
                            { title: '公司名称', field: 'companyName', width: '70%' },
                            { title: str +'成功次数', field: 'depositNumbr', width: '15%', align: 'right' },
                            {
                                field: 'depositSum',
                                title: str + '成功总额',
                                width: '15%',
                                align: 'right',
                                formatter: function (value, row, index) {
                                    return FlashPay.Util.FormatNumber(value);
                                }
                            }
                        ]]
                    });
                    treegrid.treegrid('loadData', response);

                },
                error: function (e) {
                    cover.Remove();

                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
                }
            });
        }

        $.fn.serializeObject = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };

        function DataAutoHeight() {
            $(".datagrid-header").css({
                height: $(window).height() - 70+'px'
            });
        }
    </script>
</body>
</html>
